<?
/**
 * 
 * 
 * */
class pct
{
   /**
    * 功能:de Pct ID的各项数据
    */
   static public function de($date,$id="")
   {
       is_array($date) && $date = $date["date"].$date["id"];
       $id && $date = $date.$id;
       !is_numeric($date) && $date = g::phpDeCode($date);
       $yyyy = substr($date,0,4);
       $mm = substr($date,4,2);
       $dd = substr($date,6,2);
       $id = substr($date,8);
       return array(
	       	"gid"	=>$id,
	       	"gYmd"	=>$yyyy.$mm.$dd,
	       	"yyyy"	=>$yyyy,
	       	"mm"	=>$mm,
	       	"dd"	=>$dd,
	       	"id"	=>$id,
	       	"date"	=>$date
       );
   }
   /**
    * 功能:en Pct ID的各项数据
    */
   static public function en($date,$id="")
   {
       is_array($date) && $date = $date["date"].$date["id"];
       $id && $date = $date.$id;
       is_numeric($date) && $date = g::phpEnCode($date);
       return $date;
   }
   /**
    * 功能:得到商品的URL
    * 參數:$date
    * 	   $id
    * 返回:string URL
    */
    static public function url($date,$id='')
    {
        return surl::get("www")."pct.php?id=".self::en($date,$id);
    }
    /**
    * 功能:得到商品的URL
    * 參數:$date
    * 	   $id
    * 返回:string URL
    */
    static public function url_fav($date,$id='')
    {
        return surl::get("www")."fav.php?id=".self::en($date,$id);
    }
    /**
     * 功能:得商品编缉地址
     */
    static public function modifyUrl($date,$id='')
    {
        return surl::get("my")."sell.php?step=info&id=".self::en($date,$id);
    }
    /**
     * 參數:$date
     * 	   $id
     * 返回:string URL
     */
    static public function img($date,$id='')
    {
        $arr = self::de($date,$id);
        $pctImgFileRoot = surl::get("img")."pct{$arr['yyyy']}/{$arr['mm']}/{$arr['dd']}/";
        return array($pctImgFileRoot.$arr['id']."_s.jpg",$pctImgFileRoot.$arr['id'].".jpg");
    }
    
    /**
     * 功能:得到商品图片的存放的URL
     * 參數:$date
     * 	   $id
     * 返回:array FileName
     */
    static public function imgLocalFileName($date,$id='')
    {
        $arr = self::de($date,$id);
        $pctImgFileRoot = UP_IMG_DIR."pct{$arr['yyyy']}/{$arr['mm']}/{$arr['dd']}/";
        g::dir($pctImgFileRoot,true);
		return array($pctImgFileRoot.$arr['id']."_s.jpg",$pctImgFileRoot.$arr['id'].".jpg");
    }
    /**
     * 功能:得到商品地区
     */
    static public function area(&$db,&$arr)
    {
        if($arr["gLocation"] == "1")
        {
            return $arr["gLocationExt"];
        }else
        {
            $area  = area::id2name($db,array("a1id"=>$arr["gLocationExt"]));
			return $area ? "台湾".implode("",$area) : "台湾";
        }
    }
    /**
     * 功能:得到剩时间
     */
    static public function time($t)
    {
        if($t>0)
        {
	        $rs = floor($t/86400);
	        if($rs)
	        {
	            $rs .="天".floor(($t%86400)/3600)."小时"; 
	        }else
	        {
	            $rs = floor($t/3600);
	            if($rs)
	            {
	                $rs .="小时".floor(($t%3600)/60)."分";  
	            }else
	            {
	                $rs = floor($t/3600);
		            $rs .="分".($t%60)."秒"; 
	            }
	        }
        }else
        {
            $rs = "到期下架";
        }
        return $rs;
    }
    /**
     * 功能:得运费
     */
    static public function cTransportType(&$rs,$type=0)
    {
        $t = array();
        if($type == 1)
        {
		    if($rs["cTransportType"] == 1)
		    {
				(int)$rs["dwNormalMailPrice"] && $t[] = $rs["dwNormalMailPrice"]."元(郵寄)";
				(int)$rs["dwHomeMailPrice"] && $t[] = $rs["dwHomeMailPrice"]."元(宅配)";
				(int)$rs["dwExpressMailPrice"] && $t[] = $rs["dwExpressMailPrice"]."元(快遞)";
		    }else{
				$t[] = "卖家承担运费";
		    }
        }elseif($type == 2)
        {
        	if($rs["cTransportType"] == 1)
		    {
				(int)$rs["dwNormalMailPrice"] && $t[] 	= '<input type="radio" value="dwNormalMailPrice" 	name="MailType" require="1"/>'.$rs["dwNormalMailPrice"]."元(郵寄)";
				(int)$rs["dwHomeMailPrice"] && $t[] 	= '<input type="radio" value="dwHomeMailPrice" 		name="MailType" require="1"/>'.$rs["dwHomeMailPrice"]."元(宅配)";
				(int)$rs["dwExpressMailPrice"] && $t[] 	= '<input type="radio" value="dwExpressMailPrice" 	name="MailType" require="1"/>'.$rs["dwExpressMailPrice"]."元(快遞)";
		    }else{
				$t[] = '<input name="MailType" type="hidden" value="0" />卖家承担运费';
		    }
    	}else
    	{
            if($rs["cTransportType"] == 1)
		    {
				$t = min($rs["dwNormalMailPrice"],$rs["dwHomeMailPrice"],$rs["dwExpressMailPrice"]);
			}else{
				$t = "卖家承担";
		    }
        }
        return $t;
    }
	/**
	 * 功能:得到商品的新旧程度
	 */
	static public function cNewType(&$cNewType)
	{
	    $tmp = array(
			1=>"全新",
			2=>"二手",
			4=>"陈列品"
		);
	    return $tmp[$cNewType];
	}
	/**
	 * 功能:得到商品的价格说明
	 */
	static public function cSellType_text(&$cSellType)
	{
	    $tmp = array(
			1=>"售 &nbsp;&nbsp; 价",
			2=>"当前价格"
		);
	    return $tmp[$cSellType];
	}
	static public function cSellType(&$cSellType)
	{
	    $tmp = array(
			1=>"一口价",
			2=>"拍  卖"
		);
	    return $tmp[$cSellType];
	}
	/**
	 *  功能:发票
	 */
	static public function cInvoiceType(&$cInvoiceType)
	{
	    $tmp = array(
			1=>"有发票",
			0=>"无发票"
		);
	    return $tmp[$cInvoiceType];
	}
	/**
	 * 功能:保修
	 */
	static public function cRepairType(&$cRepairType)
	{
	    $tmp = array(
			1=>"有保修",
			0=>"不保修"
		);
	    return $tmp[$cRepairType];
	}
	/**
	 * 功能:付款方式
	 */
	static public function gPayWay(&$arr)
	{
	    $rs  = array();
	    $tmp = array(
	    	"cash"=>"接受現金",
	    	"atm" =>"ATM轉帳",
	    	"check"=>"接受支票或匯款",
	    	"credit"=>"接受信用卡",
	    	"other"=>"其他"
	    );
	    $gPayWay = explode(",",$arr["gPayWay"]);
	    foreach($gPayWay as &$v)
	    {
	        if($tmp[$v])
	        {
	            if($v == "other" && $arr["gPayWayExt"])
	            {
	                $rs[] = $tmp[$v].":".$arr["gPayWayExt"];
	            }else
	            {
	                $rs[] = $tmp[$v];
	            }
	        }
	    }
	    return $rs;
	}
	/**
	 * 功能:特別標籤
	 */
	static public function gFlag(&$arr)
	{
	    $rs  = array();
	    $tmp = array(
	    	"HAND"=>"手工製品",
	    	"SPSIZE" =>"特殊尺寸",
	    	"LIMIT"=>"限量商品",
	    	"IDENT"=>"附鑑定書",
	    	"BOOKS"=>"附保證書",
	    	"STORE"=>"店面保證",
	    	"COMPANY"=>"公司貨",
	    	"GIFT"=>"適合送禮",
	    	"OFF50"=>"低於五折"
	    );
	    $gFlag = explode(",",$arr["gFlag"]);
	    foreach($gFlag as &$v)
	    {
	        if($tmp[$v]) $rs[] = $tmp[$v];
	    }
	    return $rs;
	}
   /**
    * 功能:添加商品
    * 参数:
    * 	$db 
    * 	$ArrP
    * 	$ArrG
    * 	$ArrF
    * 返回:array
    */
   static public function addPctInfo($db,$ArrP=array(),$ArrG=array(),$ArrF=array())
   {
        $cSellType = $ArrP['cSellType'];
		$time = time();
		$gYmd = date('Ymd',$time);
		//一口价与拍卖
		if($cSellType == "1")
		{
		    $dwPrice_bin = (float)$ArrP['dwPrice_bin'];
		    $dwPrice_auc = 0;
		    $cPriceToAddType = 0;
		    $dwPriceToAdd = 0;
		    $cGageMoney =0;
		    $dwForegift = 0;
		    $dwPledgeStart = 0;
		}else
		{
		    $dwPrice_auc = (float)$ArrP['dwPrice_auc'];
		    $dwPrice_bin = $dwPrice_auc;
		    //最低加价幅度
		    $cPriceToAddType = (int)$ArrP['cPriceToAddType'];
		    $dwPriceToAdd    = (float)$ArrP['dwPriceToAdd'];
		    if($cPriceToAddType)
		    {
		         $dwPriceToAdd    = (float)$ArrP['dwPriceToAdd'];
		    }else
		    {
		        $dwPriceToAdd     = 0;
		    }
		    //设置抵押金
		    $cGageMoney  = (int)$ArrP['cGageMoney'];
		    if($cGageMoney)
		    {
		        $dwForegift = (float)$ArrP['dwForegift'];
		        $dwPledgeStart = (float)$ArrP['dwPledgeStart'];
		    }else
		    {
		        $dwForegift = 0;
		        $dwPledgeStart = 0;
		    }
		}
		//上架时间
		$uploadDateExt   = 0;//这个字段先不用
		$uploadDate 	 = (int)$ArrP['uploadDate'];
		$dwValidDuration = (int)$ArrP['dwValidDuration'];
		$dwValidDuration = $dwValidDuration>14?7:$dwValidDuration;
		if($uploadDate)
		{		    
		    $upload 			= 1;
		    $uploadTimes 		= 1;
		    $uploadDate 		= $time;//上架时间
		    $dwValidDurationExt = $uploadDate +  $dwValidDuration*24*3600;//结束时间
		}else
		{
		    $upload = 0;
		    $uploadTimes = 0;
		    $uploadDate   = 0;
		    $dwValidDurationExt = 0;
		}
		//買家資格限制
		$gBuyerLimit = (int)$ArrP['gBuyerLimit'];
		if($gBuyerLimit)
		{
		    $gBuyerLimitValue = (int)$ArrP['gBuyerLimitValue'];
		}else
		{
		    $gBuyerLimitValue =0;
		}
		$cSendType = is_array($ArrP['cSendType'])?implode(',',$ArrP['cSendType']):"";
		$gPayWay   = is_array($ArrP['gPayWay'])?implode(',',$ArrP['gPayWay']):"";
		if(in_array('other',$ArrP['gPayWay']))
		{
		    $gPayWayExt = $ArrP['gPayWayExt'];
		}else
		{
		    $gPayWayExt = '';
		}
		$gDeliverWay   = is_array($ArrP['gDeliverWay'])?implode(',',$ArrP['gDeliverWay']):"";
		if(in_array('other',$ArrP['gDeliverWay']))
		{
		    $gDeliverWayExt = $ArrP['gDeliverWayExt'];
		}else
		{
		    $gDeliverWayExt = '';
		}
		//邮资
		$cTransportType =(int)$ArrP['cTransportType'];
		if($cTransportType)
		{
		    $dwNormalMailPrice 	= (float)$ArrP['dwNormalMailPrice'];
		    $dwHomeMailPrice 	= (float)$ArrP['dwHomeMailPrice'];	  
		    $dwExpressMailPrice = (float)$ArrP['dwExpressMailPrice'];	    
		}else
		{
		    $dwNormalMailPrice 	= 0;
		    $dwHomeMailPrice 	= 0;	  
		    $dwExpressMailPrice = 0;
		}
		//所在地
		$gLocation = (int)$ArrP['gLocation'];
		if(!$gLocation)
		{
		    //在台时用地区
		    $gLocationExt = (int)$ArrP['gLocationExt_1'];
		}else
		{
		    //其它地方,就不用int
		    $gLocationExt = $ArrP['gLocationExt_2'];
		}
		//标
		$gFlag = $ArrP['gFlag'];
		if(is_array($gFlag))
		{
		    $gFlag = implode(',',$gFlag);
		}else
		{
		    $gFlag = '';
		}
		$bind = array(
			'gYmd' => $gYmd,
			'c1id' =>(int)$ArrP['c1id'],                
  			'c2id' =>(int)$ArrP['c2id'],             
  			'c3id' =>(int)$ArrP['c3id'],               
  			'c4id' =>(int)$ArrP['c4id'],              
  			'urs' =>urs,                
  			'cSellType' =>$cSellType,
  			'dwPrice_bin' =>$dwPrice_bin,           
  			'dwPrice_auc' =>$dwPrice_auc,           
  			'cPriceToAddType' =>$cPriceToAddType,            
  			'dwPriceToAdd' =>$dwPriceToAdd,            
  			'cGageMoney' =>$cGageMoney,               
  			'dwForegift' =>$dwForegift,
  			'dwPledgeStart'=>$dwPledgeStart,          
  			'upload' =>$upload,         
  			'uploadDate' =>$uploadDate, 
  			'uploadDateExt' =>$uploadDateExt,          
  			'uploadTimes' =>$uploadTimes,
  			'gBuyerLimit' =>$gBuyerLimit,
  			'gBuyerLimitValue'=>$gBuyerLimitValue,       
  			'cSendType' =>$cSendType,                
  			'gPayWay' =>$gPayWay,           
  			'gPayWayExt' =>$gPayWayExt,                
  			'gDeliverWay' =>$gDeliverWay,   
  			'gDeliverWayExt' =>$gDeliverWayExt,               
  			'cTransportType' =>$cTransportType,
  			'dwNormalMailPrice' =>$dwNormalMailPrice,               
  			'dwHomeMailPrice' =>$dwHomeMailPrice,               
  			'dwExpressMailPrice' =>$dwExpressMailPrice,                
  			'dwOpNum' =>(int)$ArrP['dwOpNum'],           
  			'sTitle' =>strip_tags($ArrP['sTitle']),               
  			'dwNum' =>(int)$ArrP['dwNum'],           
  			'dwValidDuration' =>$dwValidDuration,
  			'dwValidDurationExt'=>$dwValidDurationExt,             
  			'gLocation' =>$gLocation,              
  			'gLocationExt' =>$gLocationExt,          
  			'cInvoiceType' =>(int)$ArrP['cInvoiceType'],          
  			'cNewType' =>$ArrP['cNewType'],           
  			'cRepairType' =>(int)$ArrP['cRepairType'],             
  			'gFlag' =>$gFlag,                
  			'sShopClassid' =>$ArrP['sShopClassid'],              
  			'cAutoReload' =>(int)$ArrP['cAutoReload'], 
  			'cPctStyle'=>(int)$ArrP['cPctStyle'],            
  			'gExt' =>$ArrP['gExt'],          
  			'gSavaTime' =>$time,                 
  			'gIp' =>g::ip()		
		);
		$gid = $db->insert('goods_info',$bind);
		if($gid)
		{
			$bind = array(
				'gYmd' => $gYmd,
				'gid' =>$gid,
				'urs' =>urs,
				'sDesc'=>strip_tags($ArrP['sDesc'])
			);
			$db->replace('goods_info_desc',$bind);
			//echo $db->getsql();
			//上传图档
			$pctImgFile = self::imgLocalFileName($gYmd,$gid);
			if(move_uploaded_file($ArrF['photo']['tmp_name'], $pctImgFile[1]))
			{
				$rs=img::zoom($pctImgFile[1],PCT_IMG_MW,PCT_IMG_MH,2);
				if($rs[0])
				{
					img::cut($pctImgFile[1],PCT_IMG_SW,PCT_IMG_SH,2,95,$pctImgFile[0]);
					$upImg      ="";
				}else
				{
					$upImg      = "&upImgError=1&upImgErrorNote={$rs[1]}";
				}
			}else
			{
				$upImg      = "&upImgError=1&upImgErrorNote=图上传失败!";
			}
			return array($gid,'',surl::get('my')."sell.php?step=ok{$upImg}&gid=".pct::en($gYmd.$gid));
			//g::gowin(surl::get('my')."sell.php?step=ok{$upImg}&gid=".g::phpEnCode($gYmd.$gid));
		}else
		{
			return array(0,"提示:系统繁忙,请重试!");
			//echo g::msg("提示:系统繁忙,请重试!");
			//g::gowin();
		}
   }
   /**
    * 功能:更改商品
    * 参数:
    * 	$db 
    * 	$ArrP
    * 	$ArrG
    * 	$ArrF
    * 返回:array
    */
   static public function modifyPctInfo($db,$ArrP=array(),$ArrG=array(),$ArrF=array())
   {
        $arr       = self::de($ArrP["id"]);
        $gYmd 	   = $arr["gYmd"];
        $gid	   = $arr["gid"];
        
		$time	   = time();
		$cSellType = $ArrP['cSellType'];
		//一口价与拍卖
		if($cSellType == "1")
		{
		    $dwPrice_bin = (float)$ArrP['dwPrice_bin'];
		    $dwPrice_auc = 0;
		    $cPriceToAddType = 0;
		    $dwPriceToAdd = 0;
		    $cGageMoney =0;
		    $dwForegift = 0;
		    $dwPledgeStart = 0;
		}else
		{
		    $dwPrice_auc = (float)$ArrP['dwPrice_auc'];
		    $dwPrice_bin = $dwPrice_auc;
		    //最低加价幅度
		    $cPriceToAddType = (int)$ArrP['cPriceToAddType'];
		    $dwPriceToAdd    = (float)$ArrP['dwPriceToAdd'];
		    if($cPriceToAddType)
		    {
		         $dwPriceToAdd    = (float)$ArrP['dwPriceToAdd'];
		    }else
		    {
		        $dwPriceToAdd     = 0;
		    }
		    //设置抵押金
		    $cGageMoney  = (int)$ArrP['cGageMoney'];
		    if($cGageMoney)
		    {
		        $dwForegift = (float)$ArrP['dwForegift'];
		        $dwPledgeStart = (float)$ArrP['dwPledgeStart'];
		    }else
		    {
		        $dwForegift = 0;
		        $dwPledgeStart = 0;
		    }
		}
		/*/上架时间
		$uploadDate 	 = (int)$ArrP['uploadDate'];
		$dwValidDuration = (int)$ArrP['dwValidDuration'];
		$uploadDateExt   = 0;//这个字段先不用
		$dwValidDuration = $dwValidDuration>14?1:$dwValidDuration;
		if($uploadDate)
		{		    
		    $upload 			= 1;
		    $uploadTimes 		= 1;
		    $uploadDate 		= $time;
		    $dwValidDurationExt = $uploadDate +  $dwValidDuration*24*3600;
		}else
		{
		    $upload 		= 0;
		    $uploadTimes 	= 0;
		    $uploadDateExt 	= 0;
		    $uploadDate   	= 0;
		    $dwValidDurationExt = 0;
		}
		//*/
		//買家資格限制
		$gBuyerLimit = (int)$ArrP['gBuyerLimit'];
		if($gBuyerLimit)
		{
		    $gBuyerLimitValue = (int)$ArrP['gBuyerLimitValue'];
		}else
		{
		    $gBuyerLimitValue =0;
		}
		$cSendType = is_array($ArrP['cSendType'])?implode(',',$ArrP['cSendType']):"";
		$gPayWay   = is_array($ArrP['gPayWay'])?implode(',',$ArrP['gPayWay']):"";
		if(is_array($gPayWay) && in_array('other',$gPayWay))
		{
		    $gPayWayExt = $ArrP['gPayWayExt'];
		}else
		{
		    $gPayWayExt = '';
		}
		$gDeliverWay   = is_array($ArrP['gDeliverWay'])?implode(',',$ArrP['gDeliverWay']):"";
		if(is_array($gDeliverWay) && in_array('other',$gDeliverWay))
		{
		    $gDeliverWayExt = $ArrP['gDeliverWayExt'];
		}else
		{
		    $gDeliverWayExt = '';
		}
		//邮资
		$cTransportType =(int)$ArrP['cTransportType'];
		if($cTransportType)
		{
		    $dwNormalMailPrice = 	(float)$ArrP['dwNormalMailPrice'];
		    $dwHomeMailPrice = 	(float)$ArrP['dwHomeMailPrice'];	  
		    $dwExpressMailPrice = 	(float)$ArrP['dwExpressMailPrice'];	    
		}else
		{
		    $dwNormalMailPrice = 0;
		    $dwHomeMailPrice = 0;	  
		    $dwExpressMailPrice = 0;
		}
		//所在地
		$gLocation = (int)$ArrP['gLocation'];
		if(!$gLocation)
		{
		    $gLocationExt = (int)$ArrP['gLocationExt_1'];
		}else
		{
		    $gLocationExt = (int)$ArrP['gLocationExt_2'];
		}
		//标
		$gFlag = $ArrP['gFlag'];
		if(is_array($gFlag))
		{
		    $gFlag = implode(',',$gFlag);
		}else
		{
		    $gFlag = '';
		}
		$bind = array(
			'gYmd' => $gYmd,
			'c1id' =>(int)$ArrP['c1id'],                
  			'c2id' =>(int)$ArrP['c2id'],             
  			'c3id' =>(int)$ArrP['c3id'],               
  			'c4id' =>(int)$ArrP['c4id'],              
  			'urs' =>urs,                
  			'cSellType' =>$cSellType,
  			'dwPrice_bin' =>$dwPrice_bin,           
  			'dwPrice_auc' =>$dwPrice_auc,           
  			'cPriceToAddType' =>$cPriceToAddType,            
  			'dwPriceToAdd' =>$dwPriceToAdd,            
  			'cGageMoney' =>$cGageMoney,               
  			'dwForegift' =>$dwForegift,
  			'dwPledgeStart'=>$dwPledgeStart,          
  			//'upload' =>$upload,         
  			//'uploadDate' =>$uploadDate, 
  			//'uploadDateExt' =>$uploadDateExt,          
  			//'uploadTimes' =>$uploadTimes,
  			'gBuyerLimit' =>$gBuyerLimit,
  			'gBuyerLimitValue'=>$gBuyerLimitValue,       
  			'cSendType' =>$cSendType,                
  			'gPayWay' =>$gPayWay,           
  			'gPayWayExt' =>$gPayWayExt,                
  			'gDeliverWay' =>$gDeliverWay,   
  			'gDeliverWayExt' =>$gDeliverWayExt,               
  			'cTransportType' =>$cTransportType,
  			'dwNormalMailPrice' =>$dwNormalMailPrice,               
  			'dwHomeMailPrice' =>$dwHomeMailPrice,               
  			'dwExpressMailPrice' =>$dwExpressMailPrice,                
  			'dwOpNum' =>(int)$ArrP['dwOpNum'],           
  			'sTitle' =>strip_tags($ArrP['sTitle']),               
  			'dwNum' =>(int)$ArrP['dwNum'],           
  			//'dwValidDuration' =>$dwValidDuration,
  			//'dwValidDurationExt'=>$dwValidDurationExt,             
  			'gLocation' =>$gLocation,              
  			'gLocationExt' =>$gLocationExt,          
  			'cInvoiceType' =>(int)$ArrP['cInvoiceType'],          
  			'cNewType' =>$ArrP['cNewType'],           
  			'cRepairType' =>(int)$ArrP['cRepairType'],             
  			'gFlag' =>$gFlag,                
  			'sShopClassid' =>$ArrP['sShopClassid'],              
  			'cAutoReload' =>(int)$ArrP['cAutoReload'],   
  			'cPctStyle'=>(int)$ArrP['cPctStyle'],           
  			'gExt' =>$ArrP['gExt'],          
  			'gSavaTime' =>$time,                 
  			'gIp' =>g::ip()		
		);
		$where = array(
			"str" => " urs =:urs and gYmd = :gYmd and gid =:gid ",
			"bind"=> array("urs"=>urs,"gYmd"=>$gYmd,"gid"=>$gid)
		);
		$rs = $db->update('goods_info',$bind,$where["str"],$where["bind"]);
		$bind = array(
			'gYmd' => $gYmd,
			'gid' =>$gid,
			'urs' =>urs,
			'sDesc'=>strip_tags($ArrP['sDesc'])
		);
		$db->replace('goods_info_desc',$bind);
		$rs_img = self::modifyPctImg($gYmd,$gid,$ArrF); 
		if($rs || $rs_img)
		{
			return array(1,"成功:更新成功!",surl::get('my')."sell.php?step=ok{$upImg}&gid=".pct::en($gYmd.$gid));
		}else
		{
			return array(0,"提示:系统繁忙,请重试!");
			//echo g::msg("提示:系统繁忙,请重试!");
			//g::gowin();
		}
   }
   /**
    * 功能:删除商品
    */
   static public function deletePct($db,$gYmd,$gid,$urs)
   {
       //$urs  = $urs ? $urs : urs;
       //delete img
       $pctImgFile = self::imgLocalFileName($gYmd,$gid);
       @unlink($pctImgFile[0]);
       @unlink($pctImgFile[1]);
       //delete db
       $where = array(
			"str" => " urs =:urs and gYmd = :gYmd and gid =:gid ",
			"bind"=> array("urs"=>$urs,"gYmd"=>$gYmd,"gid"=>$gid)
		);
		$info = $db->delete('shop_recommend_goods',$where["str"],$where["bind"]);
		$info = $db->delete('goods_info',$where["str"],$where["bind"]);
		$desc = $db->delete('goods_info_desc',$where["str"],$where["bind"]);
		if($info && $desc)
		{
		 	return array(1,"成功:删除商品成功!");
		}else
		{
		    return array(0,"失败:商品不存在或系统忙,如遇系统忙时请稍后再试!");
		}
   }
   /**
    * 商品上架
    */
   static public function UploadDate($db,$gYmd,$gid,$urs)
   {
   		//'dwValidDuration' =$dwValidDuration,
  		//'dwValidDurationExt'=>$dwValidDurationExt, 
  		$time  = time();    
   		$where = array(
			"str" => " urs =:urs and gYmd = :gYmd and gid =:gid ",
			"bind"=> array("urs"=>$urs,"gYmd"=>$gYmd,"gid"=>$gid)
		);
   		$rs = $db->row("select * from goods_info where {$where['str']}",$where['bind']);
   		if(!$rs["upload"] || !$rs["dwValidDurationExt"] || $rs["dwValidDurationExt"]<$time)
   		{
	   		$bind = array(
	   			"upload" =>1,
	   			"uploadDate"=>$time,
	   			"uploadTimes"=>$rs["uploadTimes"]+1,
	   			"dwValidDurationExt"=>$time+(!$rs["dwValidDuration"]?7:$rs["dwValidDuration"])*3600*24	   			
	   		);   		
			$info = $db->update('shop_recommend_goods',$bind,$where["str"],$where["bind"]);
			$info = $db->update('goods_info',$bind,$where["str"],$where["bind"]);  
   		} 	
   }
   /**
    * 商品状态
    */
   static public function statePct($db,$gYmd,$gid)
   {
       $time = time();
       $where = array(
			"str" => " gYmd = :gYmd and gid =:gid ",
			"bind"=> array("gYmd"=>$gYmd,"gid"=>$gid)
		);
   		$rs = $db->row("select * from goods_info where {$where['str']}",$where['bind']);
   		if($rs["upload"]) 
   		{
   		 	 if($rs["uploadDate"]>$time)
   		 	 {
   		 	     $db->update("goods_info",array("upload"=>0),$where['str'],$where['bind']);
   		 	 }elseif($rs["dwValidDurationExt"]<$time)
   		 	 {
   		 	     self::DownPct($db,$gYmd,$gid,$rs["urs"]);
   		 	 }
   		}else
   		{
   		     if($rs["uploadDate"]<$time && $rs["dwValidDurationExt"]>$time)
   		 	 {
   		 	     $db->update("goods_info",array("upload"=>0),$where['str'],$where['bind']);
   		 	 }
   		}
   		return false;
   }
   /**
    * 商品下架
    */
   static public function DownPct($db,$gYmd,$gid,$urs)
   {
   		//'dwValidDuration' =$dwValidDuration,
  		//'dwValidDurationExt'=>$dwValidDurationExt, 
  		$time  = time();    
   		$where = array(
			"str" => " urs =:urs and gYmd = :gYmd and gid =:gid ",
			"bind"=> array("urs"=>$urs,"gYmd"=>$gYmd,"gid"=>$gid)
		);
   		$rs = $db->row("select * from goods_info where {$where['str']}",$where['bind']);
   		if($rs["upload"])
   		{
	   		$bind = array(
	   			"upload"     =>0,
	   			"uploadDate" =>0,
	   			//"uploadTimes"=>$rs["uploadTimes"]+1,
	   			"dwValidDurationExt"=>0	   			
	   		);
	   		$info = $db->delete('shop_recommend_goods',$where["str"],$where["bind"]);
	   		$info = $db->update('goods_info',$bind,$where["str"],$where["bind"]);  
   		} 	
   }
   /**
    * 推荐商品
    */
   static public function PctGood($db,$gYmd,$gid,$urs)
   {
   		$time  = time();  
   		//是否大于6
   		$rs = $db->dataArray("select gYmd,gid,upload,dwValidDurationExt from shop_recommend_goods where urs =? ",$urs);
   		$recommend_count = 0;
   		$recommend_arr   = array();
   		foreach($rs as $v)
   		{
   		    if($v["upload"] == 1 && $v["dwValidDurationExt"]>$time)
   		    {
   		    	$recommend_count++;
   		    	$recommend_arr[] = array($v["gYmd"],$v["gid"]);
   		    }
   		}
   		if($recommend_count>=6)
   		{
   		    return array(0,"提示:小店的推荐位已满!",1);
   		}
   		//是否上架
   		$where = array(
			"str" => " urs =:urs and gYmd = :gYmd and gid =:gid ",
			"bind"=> array("urs"=>$urs,"gYmd"=>$gYmd,"gid"=>$gid)
		);
   		$rs = $db->row("select * from goods_info where {$where['str']}",$where['bind']);
   		if($rs["upload"] && $rs["dwValidDurationExt"] && $rs["dwValidDurationExt"]>$time)
   		{
	   		$db->replace("shop_recommend_goods",$rs);
	   		return array(1,"成功:商品《{$rs['sTitle']}》成功添加到小店推荐位!");	   		
   		}else
   		{
   		    return array(0,"提示:商品《{$rs['sTitle']}》状态是没有上架!");
   		}   		
   }
   /**
    * 推荐商品
    */
   static public function PctGood_del($db,$gYmd,$gid,$urs)
   {
       $where = array(
			"str" => " urs =:urs and gYmd = :gYmd and gid =:gid ",
			"bind"=> array("urs"=>$urs,"gYmd"=>$gYmd,"gid"=>$gid)
	   );
       $info = $db->delete('shop_recommend_goods',$where["str"],$where["bind"]);
   	   return array(1,"成功:下架成功!");
   }
   /**
    * 功能:改商品图片
    * 参数:
    *     $arrP
    *     $arrF
    * 返回:array
    */
   static public function modifyPctImg($gYmd,$gid,$ArrF)
   {
        $rs = array();
        $pctImgFile = self::imgLocalFileName($gYmd,$gid);
		if(move_uploaded_file($ArrF['photo']['tmp_name'], $pctImgFile[1]))
		{
			$rs=img::zoom($pctImgFile[1],PCT_IMG_MW,PCT_IMG_MH,2);
			if($rs[0])
			{
				img::cut($pctImgFile[1],PCT_IMG_SW,PCT_IMG_SH,2,95,$pctImgFile[0]);
				return array(1,"成功:图片上传成功!");
			}else
			{
				//$upImg   = "&upImgError=1&upImgErrorNote={$rs[1]}";
				return $rs;//这里返图片里的信息就可以啦
			}
		}else
		{
			//$upImg      = "&upImgError=1&upImgErrorNote=图上传失败!";
			return array(0,"提示:图上传失败!");
		}
   }
   
}
?>